<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Category extends Model
{
    use SoftDeletes;
    protected $table = 'category';
    protected $fillable=[
        'parent_id',
        'user_id',
        'slug',
        'title',
        'content',
        'summary',
        'type',
        'icon',
        'count',
        'flag',
    ];

    //子分类
    public function childs()
    {
        return $this->hasMany(Category::class,'parent_id','id');
    }
    //所有子类
    public function allChilds()
    {
        return $this->childs()->with('allChilds');
    }

    public function manyPost()
    {
        return $this->belongsToMany(Post::class,'posts_category','category_id','post_id');
    }
}
